<script>
	import {
		mapGetters,
		mapActions,
		mapMutations
	} from 'vuex'
	import config from '@/admin.config.js'
	import {
		version
	} from './package.json'
	import {
		myTimeOut
	} from '@/utils/helper.js'
	import {
		buildIntervalTask
	} from '@/utils/interval.js'
	import foodWithdrawListCommon from '@/uni_modules/food-withdraw-list/pages/layer-com/index.js'

	let cancelTask=null;
	// 头部商户钱包获取方式
	let updateHeaderWallet=null;
	export default {
		created() {
			this.clear = undefined
			this.$router.beforeEach((to,from)=>{
				console.log(to)
			})
			this.$router.afterEach(async(to,from)=>{
				await myTimeOut()
				const money_wallet_el =document.querySelector(`#money_wallet`)
				if(money_wallet_el){
					const clientRect=money_wallet_el.getBoundingClientRect()
					if(clientRect.width==0&&clientRect.height==0){
						cancelTask&&cancelTask()
					}
				}
			})
		},
		methods: {
			...foodWithdrawListCommon,
			...mapActions({
				init: 'app/init'
			}),
			clearPlatform() {
				const keysOfPlatform = uni.getStorageInfoSync().keys.filter(key => key.indexOf('platform') > -1)
				keysOfPlatform.length && keysOfPlatform.forEach(key => uni.removeStorageSync(key))
			},
			updateHeaderWallet(handler){
				cancelTask&&cancelTask();
				if(handler){
					updateHeaderWallet=handler;
				}
				cancelTask=buildIntervalTask.call(this,updateHeaderWallet,10000)
			},
		},
		onPageNotFound(msg) {
			uni.redirectTo({
				url: config.error.url
			})
		},
		onLaunch: function() {
			// #ifdef H5
			console.log(
				`%c uni-admin %c v${version} `,
				'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff',
				'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0;  color: #fff; font-weight: bold;'
			)
			// #endif
			// 线上示例使用
			// console.log('%c uni-app官方团队诚邀优秀前端工程师加盟，一起打造更卓越的uni-app & uniCloud，欢迎投递简历到 hr2013@dcloud.io', 'color: red');
			console.log('App Launch')
			if (this.$uniIdPagesStore.store.hasLogin) {
				this.init()
			}

			// 登录成功回调
			uni.$on('uni-id-pages-login-success', () => {
				this.init()
			})
		},
		onShow: function() {
			console.log('App Show')
			this.clear = setInterval(() => this.clearPlatform(), 15*60*1000)
		},
		onHide: function() {
			console.log('App Hide')
			this.clear && clearInterval(this.clear)
		}
	}
</script>

<style lang="stylus">
	@import './common/public.styl';
	@import './common/reset.styl';
	@import './common/resetStyle/uni_modules.styl';
	@import './common/layer-com-style';
</style>

<style lang="scss">
	@import '@/common/uni.css';
	@import '@/common/uni-icons.css';
	@import '@/common/admin-icons.css';
	@import '@/common/theme.scss';
</style>

